<template>
  <div>
    <div class="herdertop">
      <img src="../../assets/top.png" alt="" class="topImg" />
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>基础管理</el-breadcrumb-item>
        <el-breadcrumb-item>项目信息管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="center" style="padding-top: 0px;">
      <div class="hander">项目信息管理</div>
      <div class="orderList">
        <div class="entirety">
          <div>
            <div class="search">
              <!--  账号状态搜索信息 -->
              <div class="demo-input-suffix">
                项目编码

                <el-input
                  v-model="communityCode"
                  placeholder="输入项目编码"
                  style="width: 55%"
                ></el-input>
              </div>

              <div class="demo-input-suffix">
                归属城市
                <el-select
                  v-model="rgId"
                  placeholder="请选择"
                  @change="busstwo1"
                  style="width: 65%"
                >
                  <el-option
                    v-for="item in communityList"
                    :key="item.subRgCode"
                    :label="item.subRgName"
                    :value="item.subRgCode"
                  >
                  </el-option>
                </el-select>
              </div>
              <div class="demo-input-suffix">
                项目名称

                <el-select
                  style="width: 60%"
                  v-model="legalAccountCode"
                  :disabled="rgId === ''"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in businessArr"
                    :key="item.communityCode"
                    :label="item.communityName"
                    :value="item.communityCode"
                  >
                  </el-option>
                </el-select>
              </div>
              <div class="demo-input-suffix">
                状态

                <el-select
                  style="width: 55%"
                  v-model="status"
                  placeholder="请选择"
                >
                  <el-option label="停用" value="0"></el-option>
                  <el-option label="启用" value="1"></el-option>
                </el-select>
              </div>
            </div>
            <div class="top">
              <!--  账号状态搜索信息 -->
              <div class="demo-input-suffix" style="margin-right:35px">
                <el-button
                  style="background-color:#fd804c;color: #fff;"
                  @click.native.prevent="isSelect"
                  >查询</el-button
                >
                <el-button type="warning" @click.native.prevent="isEmpty"
                  >清空</el-button
                >
              </div>
            </div>
          </div>
        </div>
        <div class="entirety">
          <div>
            <div class="search">
              <div class="demo-input-suffix">
                城市名称

                <el-select
                  v-model="subRgCode"
                  clearable
                  placeholder="请选择"
                  @change="busstwo"
                  style="width: 65%"
                >
                  <el-option
                    v-for="item in communityList"
                    :key="item.subRgCode"
                    :label="item.subRgName"
                    :value="item.subRgCode"
                  >
                  </el-option>
                </el-select>
              </div>
              <div class="demo-input-suffix">
                项目名称
                <el-select
                  clearable
                  style="width: 60%"
                  v-model="projectCode"
                  :disabled="subRgCode === ''"
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in business"
                    :key="item.communityCode"
                    :label="item.communityName"
                    :value="item.communityCode"
                  >
                  </el-option>
                </el-select>
              </div>

              <div class="demo-input-suffix">
                <el-button
                  style="background-color:#fd804c;color: #fff;"
                  @click.native.prevent="SyncProjectInfo(projectCode)"
                  :disabled="projectCode == '' ? true : false"
                  >同步项目信息
                </el-button>
              </div>
            </div>
          </div>
        </div>
        <el-dialog title="项目信息" :visible.sync="dialogFormVisible">
          <el-divider></el-divider>
          <el-descriptions class="margin-top" :column="1">
            <el-descriptions-item label="项目编码">{{
              ProjectDetail.communityCode
            }}</el-descriptions-item>
            <el-descriptions-item label="项目名称">{{
              ProjectDetail.communityName
            }}</el-descriptions-item>
            <el-descriptions-item label="归属城市">{{
              ProjectDetail.subRgName
            }}</el-descriptions-item>
            <el-descriptions-item label="归属城市公司">
              <el-tag size="small">{{
                ProjectDetail.legalCompanyName || "暂无信息"
              }}</el-tag>
            </el-descriptions-item>
          </el-descriptions>

          <el-descriptions title="项目设置" :column="3"> </el-descriptions>
          <el-divider class="dividerTitle"></el-divider>

          <el-form :model="form">
            <el-form-item label="是否强业主认证" :label-width="formLabelWidth">
              <el-radio v-model="form.isForceOwnerApply" label="0">否</el-radio>
              <el-radio v-model="form.isForceOwnerApply" label="1">是</el-radio>
            </el-form-item>
            <el-form-item
              label="物业账单最少缴费单位"
              :label-width="formLabelWidth"
            >
              <el-select
                v-model="form.minimumPaymentMonth"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in sortList"
                  :key="item"
                  :label="item"
                  :value="item"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button
              style="background-color:#fd804c;color: #fff;"
              @click.native.prevent="
                isPreservation(form, ProjectDetail.communityCode)
              "
              >保存</el-button
            >
          </div>
        </el-dialog>

        <!--  项目信息管理列表栏位-->
        <div
          class="entirety"
          v-loading="isLoading"
          element-loading-text="数据加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-custom-class="loading_color"
        >
          <div class="footer">
            <el-table :data="tableData" style="width: 100%">
              <el-table-column prop="communityCode" label="项目编码">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.communityCode }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="communityName" label="项目名称">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.communityName }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="subRgName" label="归属城市">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.subRgName }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column prop="legalCompanyName" label="归属城市公司">
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.legalCompanyName }}
                  </div>
                </template>
              </el-table-column>

              <el-table-column prop="authStatus" label="状态">
                <template slot-scope="scope">
                  <div>
                    {{
                      scope.row.status == "0"
                        ? "停用"
                        : scope.row.status == "1"
                        ? "启用"
                        : ""
                    }}
                  </div>
                </template>
              </el-table-column>

              <el-table-column fixed="right" label="操作">
                <template slot-scope="scope">
                  <el-button
                    @click.native.prevent="isProjectDetail(scope.row)"
                    style="color: #fc9e76;"
                    type="text"
                    size="small"
                  >
                    项目信息
                  </el-button>
                  <el-button
                    @click.native.prevent="
                      isHouseDetail(scope.row.communityCode)
                    "
                    style="color: #fc9e76;"
                    type="text"
                    size="small"
                  >
                    房间信息
                  </el-button>
                  <el-button
                    @click.native.prevent="
                      isEnable(scope.row.status, scope.row.communityCode)
                    "
                    style="color: #fc9e76;"
                    type="text"
                    size="small"
                  >
                    {{
                      scope.row.status == "0"
                        ? "启用"
                        : scope.row.status == "1"
                        ? "停用"
                        : ""
                    }}
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
            <div class="block">
              <div class="left"></div>
              <div class="right">
                <el-pagination
                  layout="total, sizes, prev, pager, next, jumper"
                  class="page"
                  @size-change="sizeChangeHandle"
                  @current-change="currentChangeHandle"
                  :current-page="pageIndex"
                  :page-size="pageSize"
                  :total="total"
                >
                </el-pagination>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      subRgCode: "",
      dialogFormVisible: false,
      pageIndex: 1,
      sortList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
      pageSize: 20,
      total: 0,
      tableData: [],
      id: "",
      communityList: [],
      communityCode: "",
      projectCode: "",
      legalAccountCode: "",
      pageNum: 0,
      rgId: "",
      status: null,
      businessArr: [],
      business: [],
      isLoading: false,

      ProjectDetail: {
        communityName: "",
        legalAccountCode: "",
        legalCompanyName: "",
        subRgName: ""
      },
      form: {
        minimumPaymentMonth: null,
        isForceOwnerApply: "0"
      },
      formLabelWidth: "160px"
    };
  },
  activated() {
    this.isEmpty();
    this.DetailByPage();
    this.fetchRegionCommunityList();
  },

  methods: {
    // 更换
    busstwo1(val) {
      console.log("val,,,,,,,,,", val);
      if (val == "") {
        this.legalAccountCode = "";
      }
      // 监听城市的选择 筛选商圈的枚举
      if (val) {
        let businessArray = [];
        businessArray = this.communityList.find(item => item.subRgCode === val)
          .cityCommunityDict;
        if (businessArray) {
          this.businessArr = businessArray;
          this.legalAccountCode = "";
        }
      }
    },
    // 更换
    busstwo(val) {
      console.log("val,,,,,,,,,", val);
      if (val == "") {
        this.projectCode = "";
        this.business = [];
      }
      // 监听城市的选择 筛选商圈的枚举
      if (val) {
        let businessArray = [];
        businessArray = this.communityList.find(item => item.subRgCode === val)
          .cityCommunityDict;
        if (businessArray) {
          this.business = businessArray;
          this.projectCode = "";
        }
      }
    },
    isSelect() {
      (this.pageIndex = 1), (this.pageSize = 20), this.DetailByPage();
    },

    //同步项目信息
    SyncProjectInfo(communityCode) {
      console.log(communityCode);
      this.$http({
        url: "/pmcadmin/communityInfoManage/syncCommunityInfo",
        method: "POST",
        data: {
          communityChangeStatusDTO: {
            communityCode
          }
        }
      })
        .then(res => {
          if (res.success == 1) {
            this.$message.success("同步项目信息成功");
          } else {
            this.$message.error(res.errorMsg);
          }
        })
        .catch(err => {
          this.$message.error(err.errorMsg);
        });
    },

    isPreservation(data, communityCode) {
      console.log("data, communityCode,,,,,", data, communityCode);

      this.$http({
        url: `/pmcadmin/communityInfoManage/updateCommunitySetting`,
        method: "POST",
        data: {
          communityCode,
          minimumPaymentMonth: data.minimumPaymentMonth,
          isForceOwnerApply:
            data.isForceOwnerApply !== null
              ? Number(data.isForceOwnerApply)
              : data.isForceOwnerApply
        }
      })
        .then(res => {
          this.dialogFormVisible = false;

          if (res.success == 1) {
            this.$message.success("保存成功");
          } else {
            return this.$message.error("保存失败");
          }
        })
        .catch(_ => {
          return this.$message.error("保存失败");
        });
    },

    isEnable(e, communityCode) {
      let message = "";
      if (e == 0) {
        message = "启用成功 !";
        this.$http({
          url: `/pmcadmin/communityInfoManage/updateCommunityStatus`,
          method: "POST",
          data: {
            communityCode,
            status: 1
          }
        }).then(res => {
          if (res.success == 1) {
            this.$message({ type: "success", message });
            this.DetailByPage();
          } else {
            this.$message.error("启用失败");
          }
        });
      } else if (e == 1) {
        message = "停用成功 !";
        this.$http({
          url: `/pmcadmin/communityInfoManage/updateCommunityStatus`,
          method: "POST",
          data: {
            communityCode,
            status: 0
          }
        }).then(res => {
          if (res.success == 1) {
            this.$message({ type: "success", message });
            this.DetailByPage();
          } else {
            this.$message.error("停用失败");
          }
        });
      }
    },

    //项目详情
    isProjectDetail(data) {
      this.dialogFormVisible = true;
      this.ProjectDetail = data;
      this.$http({
        url: "/pmcadmin/communityInfoManage/getCommunitySetting",
        method: "GET",
        params: {
          communityCode: data.communityCode
        }
      }).then(res => {
        this.form = res.data;
        this.form.isForceOwnerApply = res.data.isForceOwnerApply.toString();
      });
    },
    //房屋详情
    isHouseDetail(communityCode) {
      this.$router.push({
        path: "/roomRest",
        query: {
          communityCode
        }
      });
    },
    //清空
    isEmpty() {
      (this.legalAccountCode = ""),
        (this.rgId = ""),
        (this.status = null),
        (this.pageIndex = 1),
        (this.pageSize = 20),
        this.DetailByPage();
    },
    //分页获取优惠券模板列表接口调用
    DetailByPage() {
      this.isLoading = true;

      this.$http({
        url: `/pmcadmin/communityInfoManage/getByCommunityInfoManageDTO`,
        method: "POST",
        data: {
          rgId: this.rgId,
          legalAccountCode: this.legalAccountCode,
          status: this.status !== null ? Number(this.status) : this.status,
          pageSize: this.pageSize,
          pageNum: this.pageIndex
        }
      }).then(res => {
        this.isLoading = false;

        this.tableData = res.data.list;

        this.total = parseInt(res.data.total);
      });
    },

    fetchRegionCommunityList() {
      this.$http({
        url: "/memberadmin/mgr/userCenter/fetchRegionCommunityList",
        method: "GET"
      }).then(res => {
        this.communityList = res;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;

      this.DetailByPage();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;

      this.DetailByPage();
    }
  }
};
</script>
<style scoped lang="scss">
.block {
  width: 100%;
  height: 70px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding: 0 10px 0 10px;
}
.left {
  font-size: 15px;
}
.dividerTitle {
  margin: -90px 0px 24px 0px;
}
.hander {
  width: 100%;
  height: 50px;
  line-height: 50px;
  font-size: 20px;
  font-weight: 900;
}
.balance-searchMoney {
  display: flex;
  align-items: center;
}
.input {
  flex: 1;
  margin-left: 5px;
}
.nav {
  width: 102%;
  margin-top: 12px;
  margin-left: 10px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.money {
  // height: 100px;
  background-color: #fff;
  padding: 10px;
  box-sizing: border-box;
  display: flex;
  border-radius: 6px;
  // margin-bottom: 24px !important;
}
.money div {
  color: #333;
  box-sizing: border-box;
}
.one {
  font-size: 20px;
  font-weight: 500;
  color: #000;
}
.money .two {
  font-size: 12px;
  color: #666;
  font-weight: 500;
}
.moneyRight {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
}
.moneyImg {
  width: 72px;
  height: 72px;
}
.f16 {
  font-size: 16px;
}
.moneyLeft {
  flex: 1;
  background: #f2f2f2;
  text-align: center;
  padding-top: 10px;
  padding-bottom: 10px;
}
.news {
  margin-left: 60%;
}
.orderList {
  background-color: #ebeef1;
  padding-right: 40px;
  padding-top: 1px;
  padding-bottom: 1px;
  display: block;
  font-size: 16px;
  border-radius: 20px;
  list-style-type: none;
}
.entirety {
  width: 100%;
  margin: 10px;
  height: 100%;
  padding: 10px;
  background-color: #fff;
  border-radius: 10px;
  display: flex;
  padding-left: 10px;
  .basic {
    font-size: 18px;
    font-weight: 900;
    margin-top: 2%;
    margin-bottom: 1%;
    margin-left: 1%;
  }
}
.footer {
  width: 100%;
  display: flex;
  overflow: hidden;
  flex-direction: column;
}
.page {
  margin-top: 15px;
}
.search {
  margin-bottom: 15px;
}
.top {
  display: flex;
  justify-content: space-between;
}
/deep/ .el-loading-spinner i {
  color: #fc9e76;
}
/deep/ .el-loading-spinner .el-loading-text {
  color: #fc9e76;
  margin: 3px 0;
  font-size: 14px;
}
/deep/ .el-range-editor--mini {
  height: 35px;
  width: 350px;
  text-align: center;
}
/deep/ .el-range-separator {
  line-height: 25px;
}
/deep/ .el-descriptions__body table {
  border-collapse: collapse;
  width: 100%;
  table-layout: fixed;
  margin-left: 52px;
}
/deep/ .el-divider--horizontal {
  display: block;
  height: 1px;
  width: 100%;
  margin: -18px 0px 24px 0px;
}

/deep/ .el-descriptions__title {
  line-height: 18px;
  font-size: 18px;
  font-weight: normal;
  color: #303133;
  margin-bottom: 17px;
}

.overall {
  width: 100%;
  height: auto;
  display: flex;

  justify-content: space-between;
  margin-top: 3%;
  .left {
    width: 20%;
    height: auto;
  }
  .right {
    width: 80%;
    height: auto;
  }
}
.demo-input-suffix {
  margin-left: 2%;
}
.select {
  width: 65%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .dialog-footer,
  .choice {
    margin-left: 2%;
  }
}
.herdertop {
  height: 8vh;
  display: flex;
  align-items: center;
  padding: 0 20px;
  box-sizing: border-box;
}
.topImg {
  margin-right: 20px;
}
/deep/ .itemClass .el-form-item__content {
  width: 350px;
}
.userSearch {
  display: flex;
  /deep/ .el-input__inner {
    box-sizing: border-box;
    height: 40px;
    border-radius: 0;
    width: 132px;
    border: 1px solid #dcdfe6;
  }
  /deep/ .el-icon-arrow-up:before {
    position: relative;
    top: -4px;
  }
  /deep/ .el-button {
    height: 40px;
    border-radius: 0;
    background-color: #fff;
    border: 1px solid #dcdfe6;
    border-left: none;
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    position: relative;
    .el-icon-search {
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
    }
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-right: none;
  }
  /deep/ .el-input--suffix .el-input__inner {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
  }
}
.selects {
  width: 55%;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .dialog-footer,
  .choice {
    margin-left: 2%;
  }
}
/deep/ .but {
  background: #fd7097;
  color: #fff;
  margin-bottom: 1%;
}
</style>
